package com.java.comprehensive.arithmetic.leecode.medium;

import util.ListNode;

public class LeetCode_19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummyHead = new ListNode();
        dummyHead.next = head;
        ListNode cuur = dummyHead;
        ListNode fast = dummyHead;
        n++;
        while (n-- > 0 && fast != null) {
            fast = fast.next;
        }
        while (fast != null) {
            cuur = cuur.next;
            fast = fast.next;
        }
        cuur.next = cuur.next.next;
        return dummyHead.next;
    }
}
